package com.bw.gmallpublisher.controller;


import com.bw.gmallpublisher.bean.ShopAllBean;
import com.bw.gmallpublisher.bean.ShopByHourBean;
import com.bw.gmallpublisher.service.ShopService;
import com.bw.gmallpublisher.utils.DateUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
//http://localhost:8070/gmall/getShopStatsAll?date=20241031&shop_id=5&device_type=0
//http://localhost:8070/gmall/getShopStatsByHr?date=20241031&shop_id=5&device_type=0
@RestController
@RequestMapping("/gmall/")
public class ShopController {
    @Autowired
    private ShopService shopService;

    @RequestMapping("/getShopStatsAll")
    public Object getShopStatsAll(
            @RequestParam(value = "date", defaultValue = "1") Integer date,
            @RequestParam Integer shop_id,
            @RequestParam Integer device_type
            ) {
        if (date == 1) {
            date = DateUtil.now();
        }
       ShopAllBean shop = shopService.getShopStatsAll(date,shop_id,device_type);

        return  shop;


    }

    @RequestMapping("/getShopStatsByHr")
    public Object getShopStatsByHr(
            @RequestParam(value = "date", defaultValue = "1") Integer date,
            @RequestParam Integer shop_id,
            @RequestParam Integer device_type
    ) {
        if (date == 1) {
            date = DateUtil.now();
        }
        List<ShopByHourBean> shops = shopService.getShopStatsByHr(date,shop_id,device_type);

        if (shops == null || shops.size() == 0) {
            return "";
        }



        return shops;
    }
}
